<template>
  <a-spin :spinning="loading" class="w-full pt-40 min-h-[300px]">
    <template v-if="systemConfig.isRegister && !systemConfig.isArmy">
      <div class="">来源信息</div>
      <a-form v-if="!loading" :model="formState" class="form-style-flex overflow-auto" :class="formClass" :label-col="{ style: { width: '90px' } }">
        <div v-if="showDividerBotInfo" class="mt-2">
          <div class="flex flex-wrap">
            <a-form-item label="关注项目" class="w-full">
              <SelectFocusProject v-model:value="formState.brZlxm" :disabled="formState.isCode" placeholder="请选择" />
            </a-form-item>
            <a-form-item label="客户来源" class="w-4/6">
              <SelectCustomerSource v-model:value="formState.brly" :disabled="formState.isCode" />
            </a-form-item>
            <a-form-item label="介绍人" class="w-1/3">
              <SelectTable
                v-model:value="formState.refereeEmpId"
                :disabled="formState.isCode"
                custom-input
                type="员工"
                page-size="999"
                @select="
                  (select) => {
                    formState.refereeEmpId = select?.empName
                  }
                "
              />
            </a-form-item>
            <a-form-item label="业务员" class="w-1/3">
              <SelectTable
                v-model:value="formState.brYwyName"
                :disabled="formState.isCode"
                type="员工"
                page-size="999"
                @select="onSelectEmployee('brYwy', $event)"
              />
            </a-form-item>
            <a-form-item label="负责人" class="w-1/3">
              <SelectTable
                v-model:value="formState.brFzrName"
                :disabled="formState.isCode"
                type="员工"
                page-size="999"
                @select="onSelectEmployee('brFzr', $event)"
              />
            </a-form-item>
            <a-form-item label="咨询师" class="w-1/3" :required="systemConfig.isCounselor">
              <SelectTable
                v-model:value="formState.brZxsName"
                :disabled="formState.isCode"
                type="咨询师今日接待人数"
                page-size="999"
                :search-params="{ emplbid: '14' }"
                @select="onSelectEmployee('brZxs', $event)"
                @clear="formState.brZxs = ''"
              />
            </a-form-item>
          </div>
        </div>
        <a-divider v-if="showDividerBotInfo" dashed />
      </a-form>
    </template>
    <BaseTitle title="基本信息" />
    <a-form v-if="!loading" :model="formState" class="form-style-flex overflow-auto" :class="formClass" :label-col="{ style: { width: '90px' } }">
      <a-form-item label="姓名" :class="itemClass || 'w-1/3'" required>
        <SelectTable
          v-if="!isNameInput"
          v-model:value="formState.brName"
          :type="patientType"
          :search-params="{ stdate: dayjs().format('YYYY-MM-DD'), eddate: dayjs().format('YYYY-MM-DD') }"
          custom-input
          :table-width="tableWidth"
          :maxlength="20"
          empty-close
          @select="onSelectPatient"
          @clear="onClear"
          @scan-code="emit('scanCode')"
          @input-change="getPinyin"
        />
        <a-input v-else v-model:value="formState.brName" placeholder="请输入" />
      </a-form-item>
      <a-form-item label="助记码" :class="itemClass || 'w-1/3'" required>
        <a-input v-model:value="formState.pyjm" placeholder="请输入" />
      </a-form-item>
      <a-form-item label=" " :class="itemClass || 'w-1/3'">
        <a-radio-group v-model:value="formState.brXb">
          <a-radio value="男">男</a-radio>
          <a-radio value="女">女</a-radio>
        </a-radio-group>
      </a-form-item>
      <template v-for="item in itemConfig" :key="item.label">
        <a-form-item
          v-if="showConfig[item.label]"
          :label="item.label"
          :class="item.className || itemClass"
          :required="item.required"
          :label-col="{ style: { width: item.labelCol ? item.labelCol : '90px' } }"
        >
          <template v-if="item.type === 'input'">
            <a-input
              v-if="formState.brZjlx === '身份证' && item.value === 'brSfz'"
              v-model:value="formState.brSfz"
              v-input:idcard
              placeholder="请输入身份证"
              @blur="onIdCardBlur"
            />
            <a-input v-else-if="item.label === '年龄' && item.format === 'string'" v-model:value="formState.brAge" placeholder="请输入">
              <template #addonAfter>
                <a-select v-model:value="formState.ageUnit" style="width: 60px">
                  <a-select-option value="岁">岁</a-select-option>
                  <a-select-option value="月">月</a-select-option>
                  <a-select-option value="天">天</a-select-option>
                </a-select>
              </template>
            </a-input>
            <a-input v-else-if="item.format === 'number'" v-model:value="formState[item.value]" v-input:int placeholder="请输入" />
            <a-input
              v-else-if="item.value !== 'brJtdz' && item.value !== 'brHkdz' && item.value !== 'brLxrdz'"
              v-model:value="formState[item.value]"
              placeholder="请输入"
            />
            <template v-if="item.value === 'brJtdz'">
              <SelectAddress v-model:value="formState.provincesCityDistrict" allow-clear class="!w-1/2 pr-2" />
              <a-input v-model:value="formState[item.value]" class="w-1/2" placeholder="请输入详细地址" />
            </template>
            <template v-if="item.value === 'brHkdz'">
              <SelectAddress v-model:value="formState.hkProvincesCityDistrict" allow-clear class="!w-1/2 pr-2" />
              <a-input v-model:value="formState[item.value]" class="w-1/2" placeholder="请输入户籍地址" />
            </template>
            <template v-if="item.value === 'brLxrdz'">
              <SelectAddress v-model:value="formState.lxrProvincesCityDistrict" allow-clear class="!w-1/2 pr-2" />
              <a-input v-model:value="formState[item.value]" class="w-1/2" placeholder="请输入详细地址" />
            </template>
          </template>
          <!-- 选择日期 -->
          <a-date-picker
            v-else-if="item.type === 'date'"
            v-model:value="formState[item.value]"
            :disabled-date="disabledDate"
            placeholder="请选择"
            value-format="YYYY-MM-DD"
            @keydown.enter="onDateEnter($event, item.value)"
            @change="onDateChange(item.label)"
          />
          <SelectItem
            v-else-if="item.type === 'selectItem'"
            v-model:value="formState[item.value]"
            :type="item.code"
            :show-search="!!item.showSearch"
            value-key="dictItemName"
            :trigger="item.trigger || 'focus'"
            :select-first="!!item.showSearch"
            placeholder="请选择"
            @search="$event && (item.searchValue = $event)"
            @keydown.enter="onSelectItemEnter(item)"
          />
          <SelectTags
            v-else-if="item.type === 'selectTags'"
            v-model:value="formState[item.value]"
            show-setting
            show-new
            type="医嘱字典"
            :multiple="item.multiple"
            :search-params="{ blcybh: item.label }"
            placeholder="请选择"
          />
          <!-- 过敏史 -->
          <SelectAllergyModal
            v-else-if="item.type === 'selectAllergy'"
            v-model:value="formState[item.value]"
            :br-id="formState.brId"
            :source-data="formState.patientAllergys"
            @success="formState.patientAllergys = $event.data"
          />
        </a-form-item>
      </template>
      <!-- 收费标准 -->
      <a-form-item v-if="!excludeItem.includes('收费标准') && systemConfig.isStandard && !systemConfig.isArmy" label="收费标准" class="w-1/2">
        <SelectChargeStandard v-model:value="formState.chargeStandardId" select-first />
      </a-form-item>
      <a-form-item v-if="showConfig['备注']" label="备注" class="w-full">
        <a-input v-model:value="formState.cmemo" placeholder="请输入" />
      </a-form-item>
      <a-form-item v-if="showConfig['打印备注']" label="打印备注" class="w-full">
        <a-input v-model:value="formState.cmemo2" placeholder="请输入" />
      </a-form-item>
      <template v-if="!systemConfig.isRegister && !systemConfig.isArmy">
        <a-divider v-if="showDividerBotInfo" dashed />
        <BaseTitle title="来源信息" />
        <div v-if="showDividerBotInfo" class="mt-2">
          <div class="flex flex-wrap">
            <a-form-item label="业务员" class="w-1/3">
              <SelectTable
                v-model:value="formState.brYwyName"
                :disabled="formState.isCode"
                type="员工"
                page-size="999"
                @select="onSelectEmployee('brYwy', $event)"
              />
            </a-form-item>
            <a-form-item label="咨询师" class="w-1/3" :required="systemConfig.isCounselor">
              <SelectTable
                v-model:value="formState.brZxsName"
                :disabled="formState.isCode"
                type="咨询师今日接待人数"
                page-size="999"
                :search-params="{ emplbid: '14' }"
                @select="onSelectEmployee('brZxs', $event)"
                @clear="formState.brZxs = ''"
              />
            </a-form-item>
            <a-form-item label="负责人" class="w-1/3">
              <SelectTable
                v-model:value="formState.brFzrName"
                :disabled="formState.isCode"
                type="员工"
                page-size="999"
                @select="onSelectEmployee('brFzr', $event)"
              />
            </a-form-item>
            <a-form-item label="关注项目" class="w-full">
              <SelectFocusProject v-model:value="formState.brZlxm" :disabled="formState.isCode" placeholder="请选择" />
            </a-form-item>
            <a-form-item label="客户来源" class="w-full">
              <SelectCustomerSource v-model:value="formState.brly" :disabled="formState.isCode" />
            </a-form-item>
          </div>
        </div>
      </template>
      <a-form-item label="客户标签" class="w-full">
        <CustomerLabel :br-id="formState.brId" />
      </a-form-item>
    </a-form>
  </a-spin>
</template>

<script setup>
import { nextTick, onMounted, ref, watch } from 'vue'
import { message } from 'ant-design-vue'
import dayjs from 'dayjs'
import { post } from '@/utils/request'
import SelectItem from '@/components/SelectItem'
import SelectTable from '@/components/SelectTable'
import { getSystemConfig } from '@/utils/systemConfig'
import CustomerLabel from '@/components/CustomerLabel'
import SelectFocusProject from '@/components/SelectFocusProject'
import SelectAllergyModal from '@/components/SelectAllergy'
import { get } from '@/utils/request'

const emit = defineEmits(['change', 'update:value', 'loaded', 'scanCode'])
const props = defineProps({
  value: {
    type: Object,
    default: () => ({})
  },
  patientType: {
    type: String,
    default: '患者'
  },
  itemClass: {
    desc: '表单项样式',
    type: String,
    default: 'w-1/2'
  },
  tableWidth: {
    desc: '姓名table的宽度',
    type: Number,
    default: 640
  },
  formClass: {
    desc: '表单样式',
    type: String,
    default: ''
  },
  excludeItem: {
    desc: '排除的字段',
    type: Array,
    default: () => []
  },
  showDividerBotInfo: {
    desc: '是否显示底部信息',
    type: Boolean,
    default: () => true
  },
  managementType: {
    desc: '门诊或者住院',
    type: String,
    default: '0'
  },
  //  1 选择框  0 输入框
  isNameInput: {
    desc: '姓名表单类别',
    type: Boolean,
    default: false
  },
  isBuild: {
    desc: '判断是否是建档允许生成病历号',
    type: Boolean,
    default: false
  }
})

const loading = ref(true)

const itemConfig = [
  { label: '病历号', value: 'brBlkh', type: 'input', required: true },
  { label: '证件类型', value: 'brZjlx', type: 'selectItem', code: 'DT00001' },
  { label: '证件号码', value: 'brSfz', type: 'input' },
  { label: '手术病案号', value: 'oprSn', type: 'input' },
  { label: '出生日期', value: 'brBtd', type: 'date' },
  { label: '年龄', value: 'brAge', type: 'input', format: 'string', required: true },
  { label: '手机号', value: 'brMob', type: 'input', format: 'number' },
  { label: '备用手机号', value: 'backupPhone', type: 'input', format: 'number' },
  { label: '婚姻状况', value: 'brHf', type: 'selectItem', code: 'DT00002' },
  { label: '电话', value: 'brJtdh', type: 'input' },
  { label: '邮件', value: 'brEmail', type: 'input' },
  { label: '家庭地址', value: 'brJtdz', type: 'input', className: 'w-full' },
  { label: '户籍地址', value: 'brHkdz', type: 'input', className: 'w-full' },
  { label: '邮编', value: 'brJtpostno', type: 'input', format: 'number' },
  { label: '民族', value: 'brMz', type: 'selectItem', code: 'naty', showSearch: true, trigger: 'init' },
  { label: '国籍', value: 'brGj', type: 'selectItem', code: 'DT00004', showSearch: true, trigger: 'init' },
  { label: '户籍', value: 'brJg', type: 'input' },
  { label: '身高', value: 'brSg', type: 'input', suffix: 'cm', format: 'number' },
  { label: '体重', value: 'brTz', type: 'input', suffix: 'kg', format: 'number' },
  { label: '文化程度', value: 'brWhcd', type: 'selectItem', code: 'DT00005' },
  { label: '血型', value: 'brXx', type: 'selectItem', code: 'DT00006' },
  { label: 'RH', value: 'rhxx', type: 'selectItem', code: 'DT00007' },
  { label: '人员属性', value: 'rysx', type: 'selectItem', code: 'DT00021' },
  { label: '联系人', value: 'brLxr', type: 'input' },
  { label: '联系人关系', value: 'brLxrgx', type: 'selectItem', code: 'DT00008' },
  { label: '联系人电话', value: 'brLxrdh', type: 'input' },
  { label: '联系人地址', value: 'brLxrdz', type: 'input', className: 'w-full' },
  { label: '职业', value: 'brZy', type: 'selectItem', code: 'DT00009', showSearch: true },
  { label: '工作单位', value: 'brGzdw', type: 'input' },
  { label: '工作地址', value: 'brGzdz', type: 'input' },
  { label: '政治面貌', value: 'brZzmm', type: 'selectItem', code: 'DT00010' },
  { label: '入伍日期', value: 'brRwny', type: 'date' },
  { label: '部队番号', value: 'brBdfh', type: 'input' },
  { label: '部别', value: 'brBb', type: 'input' },
  { label: '军种', value: 'brJz', type: 'selectItem', code: 'DT00022' },
  { label: '军衔', value: 'brJx', type: 'selectItem', code: 'DT00023' },
  // { label: '(年龄不足1周岁)年龄', value: 'brBzAge', type: 'input' },
  { label: '学校', value: 'school', type: 'input' },
  { label: '年级', value: 'grade', type: 'input' },
  { label: '班级', value: 'bj', type: 'input' },
  { label: '新生儿出生体重', value: 'brXsecstz', type: 'input', suffix: 'cm', format: 'number', labelCol: '120px' },
  { label: '新生儿入院体重', value: 'brXserytz', type: 'input', suffix: 'kg', format: 'number', labelCol: '120px' },
  { label: '既往史', value: 'brJws', type: 'selectTags', multiple: true, className: 'w-full' },
  { label: '过敏史', value: 'brGms', type: 'selectAllergy', multiple: true, className: 'w-full' },
  { label: '遗传史', value: 'brYcs', type: 'selectTags', multiple: true, className: 'w-full' },
  { label: '家族史', value: 'brJzs', type: 'selectTags', multiple: true, className: 'w-full' },
  { label: '月经及生育史', value: 'brYjsjsys', type: 'selectTags', multiple: true, className: 'w-full', labelCol: '100px' },
  { label: '暴露史', value: 'brBls', type: 'selectTags', multiple: true, className: 'w-full' },
  { label: '残疾情况', value: 'brCjqk', type: 'selectTags', multiple: true, className: 'w-full' },
  { label: '职业病', value: 'brZyb', type: 'selectItem', multiple: true, className: 'w-full', code: 'DT00011' }
]
const defaultValue = {
  brName: '',
  brXb: '男',
  brSfz: '',
  brMob: '',
  brLxrdz: '',
  brZjlx: '身份证',
  patientAllergys: [],
  ageUnit: '岁',
  provincesCityDistrict: getSystemConfig('OUTP_PATIENT_DEFAULT_ADDR'), // 默认省市区
  brly: getSystemConfig('DEFAULT_CUSTOMER_PATH_ID') // 默认病人来源
}
const formState = ref({ ...defaultValue })

const disabledDate = (current) => {
  return current && current > dayjs().endOf('day')
}
const onIdCardBlur = async () => {
  const idCard = formState.value.brSfz
  if (formState.value.brZjlx && formState.value.brZjlx === '身份证') {
    if (idCard && (idCard.length === 18 || idCard.length === 16)) {
      const { code, data, msg } = await post('/common/util/getCsrq', { sfzhm: idCard })
      if (code !== 0) return message.error(msg || '身份证有误')
      formState.value.brBtd = data.brBtd
      formState.value.brAge = data.brAge
      formState.value.brXb = data.brXb
      formState.value.ageUnit = calculateAgeUnit(formState.value.brBtd) || '岁'
      if (systemConfig.value.registerType === '3' && showConfig.value['病历号'] && !formState.value.brId) {
        formState.value.brBlkh = idCard
      }
    }
  }
}

const onClear = () => {
  if (getSystemConfig('OUTP_REGISTER_CLEAR_ALL_WHEN_CHANGE_PATIENT') === '1') {
    emit('update:value', {})
    formState.value = { ...defaultValue }
  }
}
const onSelectPatient = (select) => {
  formState.value = {}
  emit('update:value', {})
  nextTick(async () => {
    const { code, data = {} } = await get('/common/patient/getPatientInfo?br_id=' + select.brId)
    if (code !== 0) return message.error('获取患者信息失败')
    formState.value = {
      ...data,
      brAge: getAgeUnit(data.brAge)?.brAge,
      ageUnit: getAgeUnit(data.brAge)?.ageUnit || '岁',
      provincesCityDistrict: data?.provincesCityDistrict || getSystemConfig('OUTP_PATIENT_DEFAULT_ADDR'), // 默认省市区
      brly: data?.brly || getSystemConfig('DEFAULT_CUSTOMER_PATH_ID') // 默认病人来源
    }
    if (props.patientType === '预约患者') {
      formState.value.yylsh = select?.yylsh
    }
    formState.value.jksy = 2
    !formState.value.brBlkh && getMedicalRule()
  })
}
// 获取病历号生成规则
const getMedicalRule = async () => {
  if (systemConfig.value.registerType === '3' && showConfig.value['病历号'] && !formState.value.brBlkh && formState.value.brSfz && !formState.value.brId) {
    formState.value.brBlkh = formState.value.brSfz
    emit('update:value', { ...props.value, brBlkh: formState.value.brSfz })
    return
  }
  if (!props.isBuild && (systemConfig.value.isRule === '0' || systemConfig.value.isRule === '3')) {
    const { code, data, msg } = await post('/common/patient/getBrBlkh')
    if (code !== 0) return message.error(msg)
    if (!formState.value.brBlkh) {
      formState.value.brBlkh = data
      emit('update:value', { ...props.value, brBlkh: data })
    }
  }
}

watch(
  () => props.value.brName,
  (val) => {
    if (val) {
      formState.value = {
        brXb: '男',
        brZjlx: '身份证',
        ...props.value,
        brYwyName: props.value.brYwyName !== undefined ? props.value.brYwyName : props.value.brYwy,
        brAge: getAgeUnit(props.value.brAge)?.brAge,
        ageUnit: getAgeUnit(props.value.brAge)?.ageUnit || '岁',
        provincesCityDistrict: props.value?.provincesCityDistrict || getSystemConfig('OUTP_PATIENT_DEFAULT_ADDR'), // 默认省市区
        brly: props.value?.brly || getSystemConfig('DEFAULT_CUSTOMER_PATH_ID') // 默认病人来源
      }
      if (showConfig.value['病历号']) {
        formState.value.isBrBlkh = true
        getMedicalRule?.()
      }
    } else {
      formState.value = {
        ageUnit: '岁',
        provincesCityDistrict: getSystemConfig('OUTP_PATIENT_DEFAULT_ADDR'), // 默认省市区
        brly: getSystemConfig('DEFAULT_CUSTOMER_PATH_ID') // 默认病人来源
      }
      emit('update:value', {})
    }
  },
  {
    immediate: true
  }
)
watch(
  () => formState.value,
  (val) => {
    if (val.brName) {
      emit('change', val)
      emit('update:value', { ...props.value, ...val })
    }
  },
  { deep: true }
)
const getPinyin = async (name) => {
  const { data, code } = await post('/common/util/getPinyin', { name })
  code === 0 && (formState.value.pyjm = data)
}
const showConfig = ref({})
const getShowConfig = async () => {
  const { data, mes, code } = await post('/operation/opex/getPatientlnfoList', {
    managementType: props.managementType
  })
  if (code !== 0) return message.error(mes || '获取数据失败')
  const childrenArray = data.map((item) => item.children).flat()
  childrenArray.forEach((child) => {
    showConfig.value[child.patientInfoName] = child.status === 0
  })
  setTimeout(() => {
    loading.value = false
    emit('loaded')
  }, 100)
  systemConfig.value.isRule === '1' && (showConfig.value['病历号'] = false)
  if (showConfig.value['病历号']) {
    formState.value.isBrBlkh = true
  }
}
const onSelectEmployee = (key, select) => {
  formState.value[key + 'Name'] = select.empName
  formState.value[key] = select.empId
}
const onDateChange = (label) => {
  if (label === '出生日期' && formState.value.brZjlx === '身份证' && formState.value.brSfz) {
    //身份证出生日期
    const idCardBrd = extractBirthdateFromId(formState.value.brSfz)
    if (formState.value.brBtd !== idCardBrd) {
      message.warn('证件号码与出生日期不一致，请核对')
    }
  }
  if (label === '出生日期' && !formState.value.brSfz) {
    formState.value.brAge = calculateAge(formState.value.brBtd) || 0
    formState.value.ageUnit = calculateAgeUnit(formState.value.brBtd) || '岁'
  }
}
// 正则表达式匹配身份证号码中的出生日期部分（6到14位）
const extractBirthdateFromId = (id) => {
  const regex = /^(\d{6})(\d{8})(\w*)$/
  const match = id.match(regex)

  if (match) {
    // 提取出生日期部分并转换为年-月-日的格式
    const birthdate = `${match[2].slice(0, 4)}-${match[2].slice(4, 6)}-${match[2].slice(6, 8)}`
    return birthdate
  } else {
    return message.warn('无效的身份证号码')
  }
}
//根据日期计算年龄
const calculateAge = (birthDate) => {
  const today = new Date()
  const birthDay = new Date(birthDate)
  const timeDiff = Math.abs(today.getTime() - birthDay.getTime())
  const day = Math.round(timeDiff / (24 * 60 * 60 * 1000))
  if (day <= 365) {
    if (day <= 30) {
      return day
    } else {
      return Math.floor(day / 30)
    }
  } else {
    return Math.floor(day / 365)
  }
}
//根据日期计算年龄单位
const calculateAgeUnit = (birthDate) => {
  const today = new Date()
  const birthDay = new Date(birthDate)
  const timeDiff = Math.abs(today.getTime() - birthDay.getTime())
  const day = Math.round(timeDiff / (24 * 60 * 60 * 1000))
  if (day <= 365) {
    if (day <= 30) {
      return '天'
    } else {
      return '月'
    }
  } else {
    return '岁'
  }
}
//分别取出年龄数值和年龄单位
const getAgeUnit = (val) => {
  if (!val) return { brAge: '', ageUnit: '' }
  const charsToCheck = ['岁', '月', '天']
  const result = charsToCheck.some((char) => String(val).includes(char))
  if (result) {
    return { brAge: val.substring(0, val.length - 1), ageUnit: val.substring(val.length - 1) }
  } else {
    return { brAge: val, ageUnit: '岁' }
  }
}
const onDateEnter = (e, value) => {
  const dateString = e.target.value // 匹配YYYYMMDD格式
  const regex1 = /^\d{8}$/ // 匹配YYYYMMDD格式
  const regex2 = /^\d{4}-\d{2}-\d{2}$/ // 匹配YYYY-MM-DD格式
  const regex3 = /^\d{4}\/\d{2}\/\d{2}$/ // 匹配YYYY/MM/DD格式
  const regex4 = /^\d{4}\.\d{2}\.\d{2}$/ // 匹配YYYY.MM.DD格式
  // 检查日期字符串是否符合任何一个正则表达式
  const isValidDate = regex1.test(dateString) || regex2.test(dateString) || regex3.test(dateString) || regex4.test(dateString)
  if (isValidDate) {
    const date = dayjs(dateString).format('YYYY-MM-DD')
    formState.value[value] = date
    formState.value.brAge = calculateAge(date) || 0
    formState.value.ageUnit = calculateAgeUnit(date) || '岁'
    e.target.blur()
  }
}

const onSelectItemEnter = async (item) => {
  if (formState.value[item.value] === undefined || formState.value[item.value].indexOf(item.searchValue) === -1) {
    const { code, msg } = await post('/common/masterData/saveDictCommonItem', { dictItemName: item.searchValue, dictCommonCode: item.code })
    if (code === 0) {
      formState.value[item.value] = item.searchValue
    } else {
      message.error(msg)
    }
  }
}

const systemConfig = ref({})

onMounted(() => {
  getShowConfig()
  //排除的字段
  props.excludeItem.forEach((key) => {
    showConfig.value[key] = false
  })
  systemConfig.value = {
    isRule: getSystemConfig('OUTP_DOCUMENT_NO_GENERATE_RULE'), // 病历号生成规则 0:20240424001|1：与卡号一致|2：手工输入
    isCounselor: getSystemConfig('IS_REQUIRED_CONSULTANT') === '1', // 是否咨询师必填
    isRegister: getSystemConfig('GHDJYS') === '4', // 挂号登记样式4
    isArmy: getSystemConfig('NAVYHIS_MODE') === '1', //军用系统
    isStandard: getSystemConfig('ENABLE_CHARGE_STANDARD_MODE') === '1', // 收费标准
    registerType: getSystemConfig('GHDJYS') // 挂号登记样式
  }
})
defineExpose({
  getData: () => formState.value,
  setData: (data) => {
    formState.value = {
      ...data,
      brAge: getAgeUnit(data.brAge)?.brAge,
      ageUnit: getAgeUnit(data.brAge)?.ageUnit || '岁'
    }
  },
  getPinyin,
  getMedicalRule
})
</script>
<style lang="less" scoped></style>
